import {AbilityModel} from "../../controller/model/AbilityModel";
import Configer from "../../frame/apiModel/config/Configer";
import {FinalKey} from "../../constant/FinalConstant";
import {UnitController} from "../../controller/UnitController";
import {Logger} from "../../frame/apiModel/config/Logger";
import {UnitModel} from "../../frame/apiModel/adapterModel/model3/UnitModel";
import {ItemModel} from "../../frame/apiModel/adapterModel/model3/ItemModel";
import {PlayerModel} from "../../frame/apiModel/adapterModel/model4/PlayerModel";
import {LocModel} from "../../frame/apiModel/base/LocModel";
import {PlayerFactory} from "../../frame/PlayerFactory";
import {DataRouterUtil} from "../../utils/router/DataRouterUtil";
import {CodeUtil} from "../../frame/codeAdapter/CodeUtil";
import {AttributeEnum} from "../../frame/dataSource/DataModel";
import {Util} from "../../utils/Util";
import {AbilityUtil} from "./AbilityUtil";

export default class ExpCatchPetSkillModel extends AbilityModel {
    abilityId: string = Configer.getFinal(FinalKey.expCatchSkill) as string;

    subLv = 1;


    actionFun = (activeUnit: UnitModel, activeItem: ItemModel, targetUnit: UnitModel, targetItem: ItemModel, activePlayer: PlayerModel, targetPlayer: PlayerModel, spellId: string, spellLoc: LocModel)  => {
        let success;
        const index = UnitController.getInstance().getFirstPetNullIndex(activePlayer);
        if (index >= 0) {
            const targetLv = targetUnit.level;
            let petExp = 0
            if ((targetLv - this.subLv) > 0) {
                petExp = DataRouterUtil.getMaxExpByLv(targetLv - this.subLv);
            }
            // const random = activePlayer.getRandomInt(1, 10);
            // const exp = heroExp * (random / 100)
            // const exp = heroExp * 0.2
            const probability = activePlayer.getRandomInt(1, 100)
            success = AbilityUtil.catchPet(activeUnit, targetUnit, index, probability, petExp);
        } else {
            Logger.toastProduct('您没有空余兽栏了', activePlayer)
            success = false;
        }
        return success;
    }
}